package thread;


/**
 * @description: 继承方式来创建线程
 * @author: apple
 * @date:  2021/11/27 9:38 下午
 * @version 1.0
 **/
class Window1 extends Thread {

    // 一共5张票
    private static int ticket = 10;

    @Override
    public void run() {
        while (true) {
            if (ticket > 0) {
                System.out.println(Thread.currentThread().getName() + "，还剩：" + ticket);
                ticket--;
            } else {
                System.out.println(Thread.currentThread().getName() +"票已经卖完");
                break;
            }
        }

    }
}


public class WindowsTest2 {

    public static void main(String[] args) {
        Window1 w = new Window1();
        Window1 w2 = new Window1();
        Window1 w3 = new Window1();
        w.setName("窗口1");
        w2.setName("窗口2");
        w3.setName("窗口3");
        w.start();
        w2.start();
        w3.start();

    }
}
